$(function(){
	footerPosition();
	$(window).resize(footerPosition);
});

function footerPosition(){
	var f = $("#footer");
	var footH = f.height();
	var winH = $(window).height();
	pos = f.position();
	
	if((pos.top + footH + 40) < winH) {
		var mt = parseInt(f.css("margin-top"));
		f.css('margin-top', mt + (winH - pos.top - footH - 40));
	}
}